package cn.topcodes.tcsf.admin.commons.api.controller.query;

import cn.topcodes.tcsf.admin.commons.api.domain.ApiResponseEntity;
import cn.topcodes.tcsf.admin.commons.domain.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 通用查询API接口
 * @author unicorn
 */
public interface QueryApi<V> {
	
	/*根据实体ID获取实体对象*/
	@ApiOperation(value = "获取资源", notes = "获取资源")
	@ResponseBody
	@RequestMapping(value="get",method=RequestMethod.GET)
	ApiResponseEntity<V> get(HttpServletRequest request, @ApiParam(value="资源ID") @RequestParam(required=true) Long id);
	
	/*条件查询实体列表*/
	@ApiOperation(value = "条件查询资源列表", notes = "条件查询资源列表")
	@ResponseBody
	@RequestMapping(value="list",method=RequestMethod.GET)
	ApiResponseEntity<List<V>> list(
			HttpServletRequest request);
	
	/*分页条件查询资源列表*/
	@ApiOperation(value = "分页条件查询资源列表", notes = "分页条件查询资源列表")
	@ResponseBody
	@RequestMapping(value="page-list",method=RequestMethod.GET)
	ApiResponseEntity<Page<V>> pageList(
			HttpServletRequest request,
			@ApiParam(value="页号") @RequestParam(value="page",required=false,defaultValue="1") Integer pageNumber,
			@ApiParam(value="每页条数") @RequestParam(value="size",required=false,defaultValue="10") Integer pageSize
			);

	/*判断是否存在属性值相同的记录，除了指定ID*/
	@ApiOperation(value = "检查重复", notes = "检查重复")
	@ResponseBody
	@RequestMapping(value="exist",method=RequestMethod.GET)
	ApiResponseEntity exist(
			HttpServletRequest request,
			@ApiParam(value="ID") @RequestParam(required=false) Long id,
			@ApiParam(value="属性名称") @RequestParam(required=true) String property,
			@ApiParam(value="属性值") @RequestParam(required=true) String value
	);
}
